package com.jl.cloud.terminal.service.impl;


import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.jl.cloud.commom.base.BaseService;
import com.jl.cloud.terminal.mapper.TerminalMapper;
import com.jl.cloud.terminal.model.Terminal;
import com.jl.cloud.terminal.service.ConsumersService;
import com.jl.cloud.terminal.service.TerminalService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service("terminalServiceInner")
public class TerminalServiceImpl extends BaseService<Terminal>  implements TerminalService {

    @Resource
    private ConsumersService consumersService;

    @Override
    public List<Terminal> findAll() {
        log.info("请求进来 service{}","222222222222222");
        return  ((TerminalMapper)dao).findAll();
    }


    @Override
    public void updateTransaction() {
        Terminal terminal = new Terminal();
        terminal.setId(1);
        terminal.setTerminalName("1231");
        updateById(terminal);
        consumersService.updateTransaction(1);
        Integer i = null;
        i.toString();
    }

    @Override
    //切库事务注解,和分布式事务只能存在一个
    @DSTransactional(rollbackFor = Exception.class)
    public void overallTransaction(Integer i) {
        Terminal terminal = new Terminal();
        terminal.setId(1);
        terminal.setTerminalName(i.toString());
        updateById(terminal);
        consumersService.updateTransaction(i);
    }
}
